package com.fuqiang.nightshopadmin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fuqiang.nightshopadmin.service.IUmsResourceService;
import com.fuqiang.nightshopcommon.api.R;
import com.fuqiang.nightshopumsmodel.entity.UmsResource;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 后台资源表 前端控制器
 * </p>
 *
 * @author fuqiang
 * @since 2020-04-14
 */
@RestController
@RequestMapping("/resource")
@AllArgsConstructor
public class UmsResourceController {

    private IUmsResourceService resourceService;

    @ApiOperation("分页模糊查询后台资源")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public R<IPage<UmsResource>> list(@RequestParam(required = false) Long categoryId,
                                      @RequestParam(required = false) String nameKeyword,
                                      @RequestParam(required = false) String urlKeyword,
                                      @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        IPage<UmsResource> resourceList = resourceService.list(categoryId,nameKeyword, urlKeyword, pageSize, pageNum);
        return R.success(resourceList);
    }

    @ApiOperation("查询所有后台资源")
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    @ResponseBody
    public R<List<UmsResource>> listAll() {
        List<UmsResource> resourceList = resourceService.listAll();
        return R.success(resourceList);
    }
}

